package com.pi.pro.xcmg.am.was.web.cust.controller;


import com.pi.framework.core.service.ICrudService;
import com.pi.framework.core.util.StringUtils;
import com.pi.pro.xcmg.am.was.fac.service.InforCommonWorkService;
import com.pi.wms.entity.TwaDocAsnDetails;
import com.pi.wms.entity.TwaDocAsnHeader;
import com.pi.wms.service.AsnDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


@Slf4j
@Controller
@RequestMapping("/inbound/otasndetails")
public class OtAsnDetailsController extends BaseAsnDetailsController<TwaDocAsnDetails, Long> {


    @Override
	protected ICrudService<TwaDocAsnDetails, Long> getCrudService() {
	    return service;
	}

	@Override
	protected String getPrefix() {
		return "otasndetails";
	}

    @Override
    protected void saveSetHeaderId(TwaDocAsnDetails d, Long headerId){
        if (d==null){
            return;
        }
        if (headerId==null){
            return;
        }
        d.setHeaderId(headerId);
    }

    @Override
    protected Long getId(TwaDocAsnDetails details){
        if (details==null){
            return null;
        }
        return details.getId();
    }

    protected TwaDocAsnDetails findById(Long id){
        return this.service.findById(id);
    }

    @Override
    public String createPalletize(TwaDocAsnDetails line, TwaDocAsnHeader header){
        return this.createPalletizeByDetails(line, header);
    }

    protected String redirect(String relativeUrl) {
        if(!StringUtils.isNullOrBlank(relativeUrl) && !relativeUrl.startsWith("/")) {
            relativeUrl = "/" + relativeUrl;
        }
        return "redirect:" + this.referUrl() + relativeUrl;
    }

    protected String root(String relativeUrl) {
        if(!StringUtils.isNullOrBlank(relativeUrl) && !relativeUrl.startsWith("/")) {
            relativeUrl = "/" + relativeUrl;
        }
        return this.referUrl() + relativeUrl;
    }

    private String referUrl(){
        return "/inbound/smasndetails/";
    }

}
